home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #14 / Monster Media No. 14 (April 1996) (Monster Media, Inc.).ISO / prog_gen / instal11.zip / DIALUN.PAS < prev    next >
Pascal/Delphi Source File  |  1996-01-11  |  5KB  |  189 lines

  1. unit Dialun;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, ExtCtrls, Buttons, DdeMan;
  8.  
  9. type
  10.   TDialUninstall = class(TForm)
  11.     btUnInst: TBitBtn;
  12.     btStop: TBitBtn;
  13.     Mem_Desc: TMemo;
  14.     Bevel1: TBevel;
  15.     Bevel2: TBevel;
  16.     Tit_Desc: TLabel;
  17.     Label2: TLabel;
  18.     DdeClient: TDdeClientConv;
  19.     procedure btStopClick(Sender: TObject);
  20.     procedure Initialise(Sender: TObject);
  21.     procedure btUnInstClick(Sender: TObject);
  22.   private
  23.     { Private-dΘclarations }
  24.     First : boolean;
  25.     function  DestroyGroup (FileName : string) : integer;
  26.   public
  27.     { Public-dΘclarations }
  28.   end;
  29.  
  30. var
  31.   DialUninstall: TDialUninstall;
  32.  
  33. implementation
  34.  
  35. uses Decla,Disque,Lecture,UnAbout;
  36.  
  37. {$R *.DFM}
  38.  
  39.  
  40. (* Destroy programs group *)
  41. function TDialUninstall.DestroyGroup (FileName : string) : integer;
  42. var Tmp : integer;
  43.     Macro : string;
  44.     Cmd   : array [0 .. 255] of Char;
  45. begin
  46.  Tmp := 0;
  47.  if FileName = '' then
  48.   Tmp := 1
  49.  else
  50.  begin
  51.   Macro := Format('[DeleteGroup(%s)]', [FileName]) + #13#10;
  52.   StrPCopy (Cmd, Macro);
  53.   DDEClient.ConnectMode := DDEAutomatic;
  54.   if DDEClient.SetLink('Progman','Progman') = true then
  55.   begin
  56.    if not DDEClient.ExecuteMacro(Cmd, False) then
  57.     Tmp := 2;
  58.    DDEClient.CloseLink;
  59.   end
  60.   else
  61.    Tmp := 3;
  62.  end;
  63.  DestroyGroup := Tmp;
  64. end;
  65.  
  66.  
  67.  
  68. (* initialisation *)
  69. procedure TDialUninstall.Initialise(Sender: TObject);
  70. begin
  71.  Error := -1;
  72.  First := true;
  73.  Tit_Desc.Enabled := false;
  74.  Mem_Desc.Enabled := false;
  75.  ActiveControl := btUnInst;
  76. end;
  77.  
  78. (* UnInstall button *)
  79. procedure TDialUninstall.btUnInstClick(Sender: TObject);
  80. var Tmp : integer;
  81.     Ite : integer;
  82.     Tp1 : integer;
  83. begin
  84.  Mem_Desc.Lines.Add ('UnInstall is starting ...');
  85.  btUnInst.Enabled := false;
  86.  Tmp := ReadUnsFile;
  87.  if Tmp = 0 then
  88.  begin
  89.   btUnInst.Enabled := false;
  90.   (* how many lines ? *)
  91.   Tp1 := 0; Ite := 0;
  92.   while Tp1 < Max_Unin do
  93.   begin
  94.    Inc (Tp1);
  95.    If VUnins [Tp1].TypeCase <> -1 then
  96.     Ite := Tp1
  97.   end;
  98.   (* Begin uninstall *)
  99.   while Ite > 0 do
  100.   begin
  101.    Case VUnins [Ite].TypeCase of
  102.     0 : (* directory *)
  103.         begin
  104.          Mem_Desc.Lines.Add ('Deleting Uninstall application');
  105.          DeleteFile (VUnins [Ite].FullName + '\' + Fch_UnIns + 'INS');
  106.          DeleteFile (VUnins [Ite].FullName + '\' + Fch_UnIns + 'EXE');
  107.          Mem_Desc.Lines.Add ('Deleting directory ' + VUnins [Ite].FullName);
  108.          if DestroyDirectory (VUnins [Ite].FullName) <> 0 then
  109.          (* unable to destroy *)
  110.           Tmp := 1;
  111.         end;
  112.     1 : (* files *)
  113.         begin
  114.          Mem_Desc.Lines.Add ('Deleting file ' + VUnins [Ite].FullName);
  115.          if DeleteFile (VUnins [Ite].FullName) <> 0 then
  116.          (* unable to destroy *)
  117.           Tmp := 2;
  118.         end;
  119.     2 : (* group *)
  120.         begin
  121.          Mem_Desc.Lines.Add ('Deleting group ' + VUnins [Ite].FullName);
  122.          if DestroyGroup (VUnins [Ite].FullName) <> 0 then
  123.          (* unable to destroy *)
  124.           Tmp := 3;
  125.         end;
  126.     else
  127.      (* wrong parameter *)
  128.      Tmp := 4;
  129.    end;
  130.    Dec (Ite);
  131.   end;
  132.  end
  133.  else
  134.  (* error during read of unistall file *)
  135.   Tmp := Tmp + 4;
  136.  Error := Tmp;
  137.  btUnInst.Enabled := True;
  138.  Mem_Desc.Enabled := true;
  139.  First := false;
  140.  Mem_Desc.Lines.Add ('Uninstall is ended');
  141.  btStopClick (Sender);
  142. end;
  143.  
  144. (* button Stop *)
  145. procedure TDialUninstall.btStopClick(Sender: TObject);
  146. var Tmp : string;
  147. begin
  148.  if (Error = -1) and (btUnInst.Enabled = true) then
  149.   Close
  150.  else
  151.  begin
  152.   if btUnInst.Enabled = true then
  153.   begin
  154.    If error = 0 then
  155.    begin
  156.     Mem_Desc.Lines.Add ('UnInstall is successfull');
  157.     Final.ShowModal;
  158.     Close;
  159.    end
  160.    else
  161.    begin
  162.     Mem_Desc.Lines.Add ('UnInstall is unsuccessfull');
  163.     case Error of
  164.      1 : tmp := 'because unable to delete directory';
  165.      2 : tmp := 'because unable to delete file';
  166.      3 : tmp := 'because unable to delete group';
  167.      4 : tmp := 'because bad parameter on UnInstall file';
  168.      5 : tmp := 'because uninstall file (UNSETUP.INS) doesn''t exist';
  169.      6 : tmp := 'because unable to read line on unistall file';
  170.      7 : tmp := 'because not a number on line';
  171.      8 : tmp := 'because maximum of files reach';
  172.      9 : tmp := 'because wrong number in line';
  173.     end;
  174.     Mem_Desc.Lines.add (Tmp);
  175.     btUnInst.Enabled := false;
  176.    end;
  177.   end
  178.   else
  179.   begin
  180.    if Error <> 0 then
  181.     Close;
  182.    Mem_Desc.Lines.Add ('UnInstall cancelled by user');
  183.    btUnInst.Enabled := true;
  184.   end;
  185.  end;
  186. end;
  187.  
  188. end.
  189.